package com.kedi.journalismcenter.controller;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kedi.journalismcenter.service.HeadlineService;

/**
 * 
 * @Description: 每日头条控制层
 * @author: clx
 * @date: 2019 2019年7月11日 下午15:35:59
 */
@Controller
public class HeadlineController {

	@Autowired
	public HeadlineService service;

	final static Logger logger = LoggerFactory.getLogger(HeadlineController.class);

	/**
	 * @Description: 获取前台提交的参数，指定映射方法名为/selecthomenews
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getHomeNews")
	@ResponseBody
	public List<Map<String, Object>> getHomeNews(int pageviews, int limit) {
		if (pageviews !=0 && limit !=0) {
			int page = (pageviews - 1) * limit;
			return service.homenews(page, limit);
		} else {
			return null;
		}
	}

	/**
	 * @Description: 获取前台提交的参数，指定映射方法名为/selectinternationalnews
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getInternationnalNews")
	@ResponseBody
	public List<Map<String, Object>> getInternationnalNews(int pageviews, int limit) {
		if (pageviews !=0 && limit !=0) {
			int page = (pageviews - 1) * limit;
			return service.internationalnews(page, limit);
		} else {
			return null;
		}
	}

	/**
	 * @Description: 获取前台提交的参数，指定映射方法名为/selectprovincialnews
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getProvincialNews")
	@ResponseBody
	public List<Map<String, Object>> getProvincialNews(int pageviews, int limit) {
		if (pageviews !=0 && limit !=0) {
			int page = (pageviews - 1) * limit;
			return service.provincialnews(page, limit);
		} else {
			return null;
		}
	}

	/**
	 * @Description: 获取前台提交的参数，指定映射方法名为/selectagenews
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getAgeNews")
	@ResponseBody
	public List<Map<String, Object>> getAgeNews(int pageviews, int limit) {
		if (pageviews !=0 && limit !=0) {
			int page = (pageviews - 1) * limit;
			return service.agenews(page, limit);
		} else {
			return null;
		}
	}

	/**
	 * @Description: 获取国内新闻根据id
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getHomeNewsbyid")
	@ResponseBody
	public Map<String, Object> getHomeNewsByid(int id) {
		return service.homenewsDetailByid(id);
	}

	/**
	 * @Description: 获取国际新闻byid
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getInternationnalNewsbyid")
	@ResponseBody
	public Map<String, Object> getInternationnalNewsByid(int id) {
		return service.internationalnewsDetailByid(id);
	}

	/**
	 * @Description: 获取省内新闻byid
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getProvincialNewsbyid")
	@ResponseBody
	public Map<String, Object> getProvincialNewsByid(int id) {
		return service.provincialnewsDetailByid(id);
	}

	/**
	 * @Description: 获取老年新闻根据id
	 * @return 返回一个数据对象
	 */
	@RequestMapping("/getAgeNewsbyid")
	@ResponseBody
	public Map<String, Object> getAgeNewsByid(int id) {
		return service.agenewsDetailByid(id);
	}

	/**
	 * @Description: 创建国内新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/insertihomenewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean ihomenewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.ihomenewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("插入失败");
			return false;
		}
	}

	/**
	 * @Description: 修改国内新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/updatehomenewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean homenewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.homenewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return false;
		}
	}

	/**
	 * @Description: 创建国际新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/insertiinternationalnewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean iinternationalnewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.iinternationalnewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("插入失败");
			return false;
		}
	}

	/**
	 * @Description: 修改国际新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/updateinternationalnewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean internationalnewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.internationalnewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("插入失败");
			return false;
		}
	}

	/**
	 * @Description: 创建省内新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/insertiprovincialnewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public int iprovincialnewsPhotos(@RequestParam Map map) {
		try {
			int a = service.iprovincialnewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("插入失败");
			return 0;
		}
	}

	/**
	 * @Description: 修改省内新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/updateprovincialnewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean provincialnewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.provincialnewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return false;
		}
	}

	/**
	 * 1`
	 * 
	 * @Description: 创建老人新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/insertiagenewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean iagenewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.iagenewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return false;
		}
	}

	/**
	 * @Description: 修改老人新闻和图片资源信息
	 * @return 返回一个数据对象
	 */
	@RequestMapping(value = "/updateagenewsPhotos", method = RequestMethod.POST)
	@ResponseBody
	public boolean agenewsPhotos(@RequestParam Map map) {
		try {
			boolean a = service.agenewsPhotos(map);
			return a;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("修改失败");
			return false;
		}
	}

}
